﻿package mortal.game.view.funcPreView
{
    import Message.DB.Tables.*;
    import baseEngine.modifiers.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.mvc.core.*;

    public class FuncPreviewModule extends Window
    {
        private var _effectPlayer:EffectPlayer;
        private var _rect3d:Rect3DObject;
        private var _bmpLabel:GImageBitmap;
        private var _spTips:ToolTipSprite;
        private var _bmpTipsBg:GBitmap;
        private var _bg2d:Img2D;
        private var _icon2d:Img2D;
        private var _txt:GTextFiled;
        private var _config:TSystemTrailer;
        private const needShowModuleCodes:Array;
        private var _tmpHidePoint:Point;
        private static var _instance:FuncPreviewModule;

        public function FuncPreviewModule()
        {
            this.needShowModuleCodes = [3, 11, 13];
            this.layer = LayerManager.uiLayer;
            return;
        }// end function

        public function hideForDrama(param1:Boolean = true) : void
        {
            if (param1)
            {
                if (this._tmpHidePoint == null)
                {
                    this._tmpHidePoint = new Point();
                }
                this._tmpHidePoint.x = this.x;
                this._tmpHidePoint.y = this.y;
                this.x = -400;
            }
            else if (this._tmpHidePoint != null)
            {
                this.x = this._tmpHidePoint.x;
                this.y = this._tmpHidePoint.y;
            }
            return;
        }// end function

        public function expand() : void
        {
            this.x = 0;
            return;
        }// end function

        public function unExpand() : void
        {
            this.x = -200;
            return;
        }// end function

        private function initRect3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(false, new Rectangle(0, 0, 10, 10), this);
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        private function updateEffectPlayer() : void
        {
            var _loc_1:int = 0;
            var _loc_2:String = null;
            if (this._rect3d)
            {
                this.removeEffect();
                _loc_1 = Cache.instance.role.entityInfo.career;
                _loc_2 = "UI_test02";
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2, null, this._rect3d.renderList, false);
                this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                this._rect3d.addObject3d(this._effectPlayer, 72, 48);
                this._effectPlayer.setScale(0.8, 0.8, 0.8);
            }
            return;
        }// end function

        private function removeEffect() : void
        {
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            return;
        }// end function

        public function updateConfig(param1:TSystemTrailer) : void
        {
            AutoGuideCache.isGuideFuncPanel = false;
            if (this._config != null)
            {
                if (param1 == null || this._config.system != param1.system)
                {
                    FuncPreviewUtil.instance.checkAndGuide(this._config);
                }
            }
            this._config = param1;
            if (param1 == null)
            {
                return;
            }
            this._txt.htmlText = Language.getStringByParam(20998, param1.level.toString());
            if (param1.icon != null)
            {
                LoaderManager.instance.load(param1.icon, this.iconLoaded);
            }
            this._spTips.toolTipData = this._config;
            if (param1.icon3 != null)
            {
                LoaderHelp.setBitmapdata(param1.icon3, this._bmpLabel);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._spTips = UICompomentPool.getUICompoment(ToolTipSprite) as ToolTipSprite;
            this.addChild(this._spTips);
            this._bmpTipsBg = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._bmpTipsBg.width = 147;
            this._bmpTipsBg.height = 103;
            this._spTips.addChild(this._bmpTipsBg);
            this._bmpLabel = UIFactory.gImageBitmap(null, 26, -8, this);
            var _loc_1:* = GlobalStyle.textFormatPutong.center();
            _loc_1.size = 12;
            this._txt = UIFactory.gTextField("", 0, 78, 147, 24, this, _loc_1);
            if (_closeBtn != null)
            {
                _closeBtn.visible = false;
            }
            this.initRect3d();
            this.updateEffectPlayer();
            LoaderManager.instance.load(ImagesConst.funcPreViewBg + ".swf", this.winBgLoaded);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResizeHandler);
            return;
        }// end function

        private function iconLoaded(param1:ImageInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = param1.bitmapData;
            if (this._icon2d)
            {
                this._icon2d.dispose(false);
            }
            this._icon2d = new Img2D(null, _loc_2, new Rectangle(0, 0, _loc_2.width, _loc_2.height), true);
            this._icon2d.autoDispose = false;
            this._rect3d.addImg(this._icon2d);
            return;
        }// end function

        private function winBgLoaded(param1:SWFInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = param1.bitmapData;
            if (this._bg2d)
            {
                this._bg2d.dispose(false);
            }
            this._bg2d = new Img2D(null, _loc_2, new Rectangle(0, 0, _loc_2.width, _loc_2.height), true);
            this._bg2d.autoDispose = false;
            this._rect3d.addImg(this._bg2d);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            return;
        }// end function

        private function stageResizeHandler(param1) : void
        {
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            y = Math.min(220, Global.stage.stageHeight - 410);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            Dispatcher.removeEventListener(EventName.StageResize, this.stageResizeHandler);
            this.removeEffect();
            Rect3DManager.instance.disposeRect3d(this._rect3d);
            this._rect3d = null;
            this._spTips.dispose(param1);
            this._spTips = null;
            this._txt.dispose(param1);
            this._txt = null;
            this._bmpTipsBg.dispose(param1);
            this._bmpTipsBg = null;
            this._bmpLabel.dispose(param1);
            this._bmpLabel = null;
            return;
        }// end function

        public static function get instance() : FuncPreviewModule
        {
            if (_instance == null)
            {
                _instance = new FuncPreviewModule;
            }
            return _instance;
        }// end function

        public static function hasInstanceShowing() : Boolean
        {
            if (_instance == null)
            {
                return false;
            }
            return !_instance.isHide;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
